\documentclass{article}

\begin{document}
    \foo this is an error
    \label{foo}
    \ref{foo}
\end{document}
